// JavaScript Document

//var appResult="null";


    var connectBridge = function (callback) {
        try {
            if (window.TestJavascriptBridge) {
                callback(TestJavascriptBridge);
            }

            
            else {
                document.addEventListener("TestJavascriptBridgeReady", function () {
                    callback(TestJavascriptBridge);
                }, false);
            }
            
        } catch (ex) { }
    };





    /*app native调用本页面方法*/
    connectBridge(function(bridge) {
        bridge.init(function(message, responseCallback) {

        });



        bridge.registerHandler("appdata", function(data, responseCallback) {
            
			AppData(data)
			//document.write(appResult)
			//responseCallback("receive init");
            /*弹窗*/
			//Toast.makeText("hello","SHORT")
            //alert("hello")
        });

    })



//Toast.MakeText
      var Toast ={
      makeText : function (msg , length) {
      if(!msg) {
        msg=""
      }
connectBridge(function (bridge) {
                if (typeof bridge === "undefined") {
                    return;
                }
                var json={"params":[msg,length]};
                var jsonstr=JSON.stringify(json);

                bridge.callHandler("toast", jsonstr);
            });

            },
            };


//File Class
      var File ={
      listFiles : function (path) {
      if(!path) {
        path=""
      }
connectBridge(function (bridge) {
                if (typeof bridge === "undefined") {
                    return;
                }
                var json={"params":[path]};
                var jsonstr=JSON.stringify(json);

                bridge.callHandler("listFiles", jsonstr);
            });

            },
		  
		  readFile :function (path){
			  connectBridge(function(bridge){
				  if(typeof bridge === "undefined"){
					  return;
				  }
				  var json={"params":[path]};
				  var jsonstr=JSON.stringify(json);
				  bridge.callHandler("ReadFile",jsonstr)
			  })
		  }
		  
		  
            };






//解析文件路径
//返回用法[index].path
var DataParse={
	getFiles: function (data){
		return JSON.parse(data)
	}
}


